home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
prolog
/
sbprolog
/
amiga
/
c_src2_5.zoo
/
init.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-16
|
6KB
|
213 lines
/************************************************************************
* *
* The SB-Prolog System *
* Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987 *
* *
************************************************************************/
/*-----------------------------------------------------------------
SB-Prolog is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing. Refer to the SB-Prolog General Public
License for full details.
Everyone is granted permission to copy, modify and redistribute
SB-Prolog, but only under the conditions described in the
SB-Prolog General Public License. A copy of this license is
supposed to have been given to you along with SB-Prolog so you
can know your rights and responsibilities. It should be in a
file named COPYING. Among other things, the copyright notice
and this notice must be preserved on all copies.
------------------------------------------------------------------ */
/* init.c */
/* modification history --------------------------------------------
07/16/89 - RNK - Use <string.h> instead of <strings.h> when AMIGA
is defined.
RNK = Nick Kline
*******************************/
#include "sim.h"
#include "inst.h"
#include "aux.h"
#ifndef AMIGA
#include <strings.h>
#endif
int maxmem = 100000; /* 100000 */
int maxpspace = 75000;
int maxtrail;
int d_trace;
int d_hitrace;
extern char *malloc();
/****************************************************************************/
init_sim(argc, argv)
int argc;
char *argv[];
{
int i, itmp, tempint;
char perm = PERM;
word *insert(), *temp;
char c, *charp;
/* for debugging malloc on sun (include /usr/lib/debug/malloc.o in link)
malloc_debug(2); */
for ( i = 0; i < bucket_chain; i++ ) {
temp = (word *)&hash_table[i][TEMP]; make_free(*temp);
temp = (word *)&hash_table[i][PERM]; make_free(*temp);
}
trace = hitrace = disassem = num_line = trace_sta =
d_trace = d_hitrace = call_intercept = 0;
interrupt_code = 0;
maxtrail = maxmem / 5;
if (argc == 1) quit("Usage: sbprolog [-Ttdns] [-m s_size] [-p p_size] [-b tr_size] [-ui num] bytecode_file_name ...\n");
for (i=1; i<argc; i++) {
if (*argv[i] == '-') {
charp = argv[i];
while (c = *++charp) {
switch(c) {
case 't': trace = d_trace = 1;
break;
case 'T': hitrace = d_hitrace = 1;
case 's': trace_sta = 1;
call_intercept = 1;
break;
case 'n': num_line = 1;
break;
case 'd': disassem = 1;
break;
case 'm': i++;
sscanf(argv[i], "%d", &maxmem);
maxtrail = maxmem / 5;
break;
case 'p': i++;
sscanf(argv[i], "%d", &maxpspace);
break;
case 'b': i++;
sscanf(argv[i], "%d", &maxtrail);
break;
case 'u': i++; /* skip user field on this pass */
charp++;
break;
default : printf("Unknown option %c\n", c);
}
}
}
} /* for */
pspace = (pw) (malloc(maxpspace*sizeof(word)));
if (!pspace) quit("Not enough core!\n");
max_fence = (byte *)(pspace+maxpspace);
memory = (pw) (malloc(maxmem*sizeof(word)));
if (!memory) quit("Not enough core!\n");
tstack = (pw) (malloc(maxtrail*sizeof(word)));
if (!tstack) quit("Not enough core!\n");
heap_bottom = memory;
local_bottom = memory + maxmem;
trail_bottom = tstack + maxtrail;
breg = ereg = mlocaltop = local_bottom - 2;
hreg = mheaptop = heap_bottom;
trreg = mtrailtop = trail_bottom - 1;
hbreg = heap_bottom - 1;
curr_fence = (byte *)pspace;
*(curr_fence) = fail;
trap_vector[0] = curr_fence;
curr_fence += 2;
*(curr_fence) = halt; /* set halt instruction */
*(byte **)(local_bottom - 1) = curr_fence; /* halt on final failure */
cpreg = curr_fence; /* halt on final success */
curr_fence += 2;
temp = insert("[]", 2, 0, &perm);
nil_sym = (word)temp | CS_TAG;
temp = insert(".", 1, 2, &perm);
list_str = (word)temp | CS_TAG;
list_psc = (struct psc_rec *)follow(temp);
temp = insert(",", 1, 2, &perm);
comma_psc = (struct psc_rec *)follow(temp);
temp = insert("_$interrupt", 11, 2, &perm);
interrupt_psc = (struct psc_rec *)follow(temp);
trap_vector[1] = 0;
inst_begin = 0;
/* now strip off user parameters */
for (i=0;i<10;i++) { flags[i] = nil_sym; }
for (i=1; i<argc; i++) {
if (*argv[i] == '-') {
charp = argv[i];
while (c = *++charp) {
switch(c) {
case 'p':
case 'b':
case 'm': i++;
case 't':
case 'T':
case 's':
case 'n':
case 'd': break;
case 'u': itmp = *++charp - '0';
i++; /* value; retrieved by flags(index+10,V) */
if (*argv[i]>=48 && *argv[i]<=57) { /*num*/
sscanf(argv[i], "%d", &tempint);
flags[itmp] = makeint(tempint);
}
else { /* make it a constant */
temp = insert(argv[i], strlen(argv[i]),
0, &perm);
flags[itmp] = (word)temp | CS_TAG;
}
break;
}
}
}
} /* for */
} /* init_sym */
/****************************************************************************/
init_loading(argc, argv)
int argc;
char *argv[];
{
char c;
int i;
int n = 0; /* number of the initial loaded files */
for (i=1; i<argc; i++) {
if (*argv[i] == '-') {
c = *(argv[i] + 1);
switch(c) {
case 'u':
case 'm':
case 'p':
case 'b': i++;
default : break;
}
}
else {
if (loader(argv[i])) quit("Error in loading initial files\n");
n++;
}
} /* for */
if (n == 0) quit("No input file!\n");
} /* init_system */